/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.spreedairy.portal.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.spreedairy.portal.model.CustomField;
import com.spreedairy.portal.model.CustomFieldModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the CustomField service. Represents a row in the &quot;spreedairy_CustomField&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.spreedairy.portal.model.CustomFieldModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link CustomFieldImpl}.
 * </p>
 *
 * @author SpreeDairy
 * @see CustomFieldImpl
 * @see com.spreedairy.portal.model.CustomField
 * @see com.spreedairy.portal.model.CustomFieldModel
 * @generated
 */
public class CustomFieldModelImpl extends BaseModelImpl<CustomField>
	implements CustomFieldModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a custom field model instance should use the {@link com.spreedairy.portal.model.CustomField} interface instead.
	 */
	public static final String TABLE_NAME = "spreedairy_CustomField";
	public static final Object[][] TABLE_COLUMNS = {
			{ "recId", Types.BIGINT },
			{ "categoryId", Types.BIGINT },
			{ "keyValue", Types.VARCHAR },
			{ "keyType", Types.VARCHAR },
			{ "optional", Types.BOOLEAN },
			{ "optionsValue", Types.VARCHAR },
			{ "fieldOrder", Types.INTEGER }
		};
	public static final String TABLE_SQL_CREATE = "create table spreedairy_CustomField (recId LONG not null primary key,categoryId LONG,keyValue VARCHAR(75) null,keyType VARCHAR(75) null,optional BOOLEAN,optionsValue VARCHAR(75) null,fieldOrder INTEGER)";
	public static final String TABLE_SQL_DROP = "drop table spreedairy_CustomField";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.spreedairy.portal.model.CustomField"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.spreedairy.portal.model.CustomField"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.spreedairy.portal.model.CustomField"),
			true);
	public static long CATEGORYID_COLUMN_BITMASK = 1L;
	public static long FIELDORDER_COLUMN_BITMASK = 2L;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.spreedairy.portal.model.CustomField"));

	public CustomFieldModelImpl() {
	}

	public long getPrimaryKey() {
		return _recId;
	}

	public void setPrimaryKey(long primaryKey) {
		setRecId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_recId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return CustomField.class;
	}

	public String getModelClassName() {
		return CustomField.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("recId", getRecId());
		attributes.put("categoryId", getCategoryId());
		attributes.put("keyValue", getKeyValue());
		attributes.put("keyType", getKeyType());
		attributes.put("optional", getOptional());
		attributes.put("optionsValue", getOptionsValue());
		attributes.put("fieldOrder", getFieldOrder());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long recId = (Long)attributes.get("recId");

		if (recId != null) {
			setRecId(recId);
		}

		Long categoryId = (Long)attributes.get("categoryId");

		if (categoryId != null) {
			setCategoryId(categoryId);
		}

		String keyValue = (String)attributes.get("keyValue");

		if (keyValue != null) {
			setKeyValue(keyValue);
		}

		String keyType = (String)attributes.get("keyType");

		if (keyType != null) {
			setKeyType(keyType);
		}

		Boolean optional = (Boolean)attributes.get("optional");

		if (optional != null) {
			setOptional(optional);
		}

		String optionsValue = (String)attributes.get("optionsValue");

		if (optionsValue != null) {
			setOptionsValue(optionsValue);
		}

		Integer fieldOrder = (Integer)attributes.get("fieldOrder");

		if (fieldOrder != null) {
			setFieldOrder(fieldOrder);
		}
	}

	public long getRecId() {
		return _recId;
	}

	public void setRecId(long recId) {
		_recId = recId;
	}

	public long getCategoryId() {
		return _categoryId;
	}

	public void setCategoryId(long categoryId) {
		_columnBitmask |= CATEGORYID_COLUMN_BITMASK;

		if (!_setOriginalCategoryId) {
			_setOriginalCategoryId = true;

			_originalCategoryId = _categoryId;
		}

		_categoryId = categoryId;
	}

	public long getOriginalCategoryId() {
		return _originalCategoryId;
	}

	public String getKeyValue() {
		if (_keyValue == null) {
			return StringPool.BLANK;
		}
		else {
			return _keyValue;
		}
	}

	public void setKeyValue(String keyValue) {
		_keyValue = keyValue;
	}

	public String getKeyType() {
		if (_keyType == null) {
			return StringPool.BLANK;
		}
		else {
			return _keyType;
		}
	}

	public void setKeyType(String keyType) {
		_keyType = keyType;
	}

	public boolean getOptional() {
		return _optional;
	}

	public boolean isOptional() {
		return _optional;
	}

	public void setOptional(boolean optional) {
		_optional = optional;
	}

	public String getOptionsValue() {
		if (_optionsValue == null) {
			return StringPool.BLANK;
		}
		else {
			return _optionsValue;
		}
	}

	public void setOptionsValue(String optionsValue) {
		_optionsValue = optionsValue;
	}

	public int getFieldOrder() {
		return _fieldOrder;
	}

	public void setFieldOrder(int fieldOrder) {
		_columnBitmask |= FIELDORDER_COLUMN_BITMASK;

		if (!_setOriginalFieldOrder) {
			_setOriginalFieldOrder = true;

			_originalFieldOrder = _fieldOrder;
		}

		_fieldOrder = fieldOrder;
	}

	public int getOriginalFieldOrder() {
		return _originalFieldOrder;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			CustomField.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public CustomField toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (CustomField)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		CustomFieldImpl customFieldImpl = new CustomFieldImpl();

		customFieldImpl.setRecId(getRecId());
		customFieldImpl.setCategoryId(getCategoryId());
		customFieldImpl.setKeyValue(getKeyValue());
		customFieldImpl.setKeyType(getKeyType());
		customFieldImpl.setOptional(getOptional());
		customFieldImpl.setOptionsValue(getOptionsValue());
		customFieldImpl.setFieldOrder(getFieldOrder());

		customFieldImpl.resetOriginalValues();

		return customFieldImpl;
	}

	public int compareTo(CustomField customField) {
		long primaryKey = customField.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		CustomField customField = null;

		try {
			customField = (CustomField)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = customField.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		CustomFieldModelImpl customFieldModelImpl = this;

		customFieldModelImpl._originalCategoryId = customFieldModelImpl._categoryId;

		customFieldModelImpl._setOriginalCategoryId = false;

		customFieldModelImpl._originalFieldOrder = customFieldModelImpl._fieldOrder;

		customFieldModelImpl._setOriginalFieldOrder = false;

		customFieldModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<CustomField> toCacheModel() {
		CustomFieldCacheModel customFieldCacheModel = new CustomFieldCacheModel();

		customFieldCacheModel.recId = getRecId();

		customFieldCacheModel.categoryId = getCategoryId();

		customFieldCacheModel.keyValue = getKeyValue();

		String keyValue = customFieldCacheModel.keyValue;

		if ((keyValue != null) && (keyValue.length() == 0)) {
			customFieldCacheModel.keyValue = null;
		}

		customFieldCacheModel.keyType = getKeyType();

		String keyType = customFieldCacheModel.keyType;

		if ((keyType != null) && (keyType.length() == 0)) {
			customFieldCacheModel.keyType = null;
		}

		customFieldCacheModel.optional = getOptional();

		customFieldCacheModel.optionsValue = getOptionsValue();

		String optionsValue = customFieldCacheModel.optionsValue;

		if ((optionsValue != null) && (optionsValue.length() == 0)) {
			customFieldCacheModel.optionsValue = null;
		}

		customFieldCacheModel.fieldOrder = getFieldOrder();

		return customFieldCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(15);

		sb.append("{recId=");
		sb.append(getRecId());
		sb.append(", categoryId=");
		sb.append(getCategoryId());
		sb.append(", keyValue=");
		sb.append(getKeyValue());
		sb.append(", keyType=");
		sb.append(getKeyType());
		sb.append(", optional=");
		sb.append(getOptional());
		sb.append(", optionsValue=");
		sb.append(getOptionsValue());
		sb.append(", fieldOrder=");
		sb.append(getFieldOrder());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(25);

		sb.append("<model><model-name>");
		sb.append("com.spreedairy.portal.model.CustomField");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>recId</column-name><column-value><![CDATA[");
		sb.append(getRecId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>categoryId</column-name><column-value><![CDATA[");
		sb.append(getCategoryId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyValue</column-name><column-value><![CDATA[");
		sb.append(getKeyValue());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>keyType</column-name><column-value><![CDATA[");
		sb.append(getKeyType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>optional</column-name><column-value><![CDATA[");
		sb.append(getOptional());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>optionsValue</column-name><column-value><![CDATA[");
		sb.append(getOptionsValue());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>fieldOrder</column-name><column-value><![CDATA[");
		sb.append(getFieldOrder());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = CustomField.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			CustomField.class
		};
	private long _recId;
	private long _categoryId;
	private long _originalCategoryId;
	private boolean _setOriginalCategoryId;
	private String _keyValue;
	private String _keyType;
	private boolean _optional;
	private String _optionsValue;
	private int _fieldOrder;
	private int _originalFieldOrder;
	private boolean _setOriginalFieldOrder;
	private long _columnBitmask;
	private CustomField _escapedModelProxy;
}